package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.constants.RabbitMqConst;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.util.JsonUtil;
import com.atguigu.gmall.feign.order.OrderFeignClient;
import com.atguigu.gmall.model.order.OrderInfo;
import org.checkerframework.checker.units.qual.A;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2024/10/13 5:22
 */
@Controller
public class PayController {
    @Autowired
    OrderFeignClient orderFeignClient;
    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/pay.html")
    public String payPage(@RequestParam("orderId") Long orderId, Model model){
        //TODO 远程调用orderInfo
        Result<OrderInfo> orderInfo = orderFeignClient.getOrderInfoById(orderId);
        model.addAttribute("orderInfo",orderInfo.getData());
        return "payment/pay";
    }
    @GetMapping("/pay/success.html")
    public String paySuccess(@RequestParam("out_trade_no") String out_trade_no){
        //orderFeignClient.checkOrderStatus(out_trade_no);
        //用mq来发送消息
        rabbitTemplate.convertAndSend(RabbitMqConst.ORDER_EVENT_EXCHANGE,RabbitMqConst.ORDER_RK_PAID, out_trade_no);
        return "payment/success";
    }
}
